package com.exartisan.network;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.exartisan.bean.Event;
import com.exartisan.bean.Gallery;
import com.exartisan.bean.GalleryContent;

public class ResponseStranslater {
	
	public static ArrayList<Event> translateTopEventResponse(String jsonResponse){
		ArrayList<Event> alEvent = new ArrayList<Event>();
		long eventID;
		int type; //0: top event | 1: new event
		String eventName;
		String startDate;
		String endDate;
		String thumbUrl;
		try {
			JSONArray  jsonRp =  new JSONArray(jsonResponse);
			for (int i = 0; i < jsonRp.length(); i++) {
				JSONObject jsonEvent = jsonRp.getJSONObject(i);
				eventID = jsonEvent.getLong(NetworkUtility.ID);
				type = jsonEvent.getInt(NetworkUtility.TYPE);
				eventName = jsonEvent.getString(NetworkUtility.EVENTNAME);
				startDate = jsonEvent.getString(NetworkUtility.STARTDATE);
				endDate = jsonEvent.getString(NetworkUtility.ENDDATE);
				thumbUrl = jsonEvent.getString(NetworkUtility.THUMBURL);
//				alEvent.add(new Event(eventID, type, eventName, startDate, endDate, thumbUrl));
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return alEvent;
	}
	
	public static ArrayList<Event> translateNewEventResponse(String jsonResponse){
		ArrayList<Event> alEvent = new ArrayList<Event>();
		long eventID;
		int type; //0: top event | 1: new event
		String eventName;
		String startDate;
		String endDate;
		String thumbUrl;
		String description;
		try {
			JSONArray  jsonRp =  new JSONArray(jsonResponse);
			for (int i = 0; i < jsonRp.length(); i++) {
				JSONObject jsonEvent = jsonRp.getJSONObject(i);
				eventID = jsonEvent.getLong(NetworkUtility.ID);
				type = jsonEvent.getInt(NetworkUtility.TYPE);
				eventName = jsonEvent.getString(NetworkUtility.EVENTNAME);
				startDate = jsonEvent.getString(NetworkUtility.STARTDATE);
				endDate = jsonEvent.getString(NetworkUtility.ENDDATE);
				thumbUrl = jsonEvent.getString(NetworkUtility.THUMBURL);
				description = jsonEvent.getString(NetworkUtility.DESCRIPTION);
				alEvent.add(new Event(eventID, type, eventName, startDate, endDate, thumbUrl, description));
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return alEvent;
	}
	
	public static ArrayList<Gallery> translateGalleryInfoResponse(String jsonResponse){
		ArrayList<Gallery> galleries = new ArrayList<Gallery>();
		long galleryID;
		long eventID;
		String eventName;
		String thumbURL;
		try {
			JSONArray jsonRp = new JSONArray(jsonResponse);
			for (int i = 0; i < jsonRp.length(); i++) {
				JSONObject jsonGallery = jsonRp.getJSONObject(i);
				galleryID = jsonGallery.getLong(NetworkUtility.ID);
				eventID = jsonGallery.getLong(NetworkUtility.EVENTID);
				eventName = jsonGallery.getString(NetworkUtility.EVENTNAME);
				thumbURL = jsonGallery.getString(NetworkUtility.THUMBURL);
				galleries.add(new Gallery(galleryID, eventID, eventName, thumbURL));
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return galleries;
	}
	
	
	
}
